<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>注册</title>
    <meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" name="viewport" />
    <meta content="black" name="apple-mobile-web-app-status-bar-style" />
    <meta content="telephone=yes" name="format-detection" />
    <link href="css/index.css" rel="stylesheet" type="text/css">
    <link href="css/registered.css" rel="stylesheet" type="text/css">
    <script src="js/jquery-1.8.3.min.js"></script>
    <script src="js/layer/layer.js"></script>
    <script src="js/jquery.md5.js"></script>
</head>
<body>
<div class="viewport">
    <div class="header">
        <div class="header-1"><a href="registered.html"><img src="images/u15.png"></a></div>
        <div class="header-2">注册新用户</div>
        <div class="header-3"><div class="header-3-1"></div> </div>
    </div>
    <div class="blank"></div>
    <div class="content">
        <div class="content2">
            <div class="content2-1"><span class="content2-1-1">注册号码：</span><span class="content2-1-2" id="username"></span></div>
            <div class="content2-6"><input type="checkbox" id="check"><span>同时完成个人企业账号注册</span></div>
            <div class="content2-7">
                <div class="content2-7-1"><input type="radio" id="check1" name="radio" checked="checked"><span>购销商</span></div>
                <div class="content2-7-2"><input type="radio" id="check2" name="radio"><span>餐饮企业</span></div>
            </div>
            <div class="content2-2"><input type="text" placeholder="请输入短信验证码" maxlength="6px" id="sms" class="content2-2-1"><input type="button" value="获取短信验证码" id="btn" class="btn"> </div>
            <div class="content2-3"><input type="text" placeholder="请输入真实姓名" maxlength="10px" id="trueName"></div>
            <div class="content2-3"><input type="password" placeholder="设置密码" maxlength="25px" id="password"></div>
            <div class="content2-3"><input type="password" placeholder="确认密码" maxlength="25px" id="again"></div>
            <div class="content2-4"><input type="checkbox" id="checkbox" checked="checked"><a href="javascript:void(0)" id="protocol">用户协议</a><img src="images/u33.png"> </div>
            <div class="content2-5"><input type="button" value="提 交" id="submit"></div>
        </div>
    </div>
</div>
</body>
</html>
<script type="text/javascript">
    /*隐藏层*/
    $(function(){
        $("#check").click(function(){
            $(".content2-7").addClass("block").siblings().removeClass("block");

        })
    });
    /*用户协议*/
    $(function(){
        $("#protocol").click(function(){
            layer.open({
                type:2,
                title:"《快来网络用户注册协议》",
                shadeClose:true,
                shade:0.2,
                area:["90%","60%"],
                content:"UserAgreement.html"
            })
        })
    });
    /*获取验证码时间*/
    $(function(){
        var wait=60;
        function time(o) {
            if (wait == 0) {
                o.removeAttribute("disabled");
                o.value="免费获取验证码";
                wait = 60;
            } else {
                o.setAttribute("disabled", true);
                o.value="重新发送(" + wait + ")";
                wait--;
                setTimeout(function() {
                            time(o)
                        },
                        1000)
            }
        }
        $("#btn").click(function(){time(this);});
    });
    /*注册*/
    $(function(){
        var url = location.search;
        if (url.indexOf("?") != -1) {
            var str = url.substr(1);
            strs = str.split("&");
            for(var i = 0; i < strs.length; i ++) {
                $("#username").text(strs);
                $("#submit").click(function(){
                    var username=$("#username").text();
                    var sms=$("#sms").val();
                    var check=$("#check").prop("checked");
                    var check1=$("#check1").prop("checked");
                    var check2=$("#check2").prop("checked");
                    var trueName=$("#trueName").val();
                    var password=$("#password").val();
                    var again=$("#again").val();
                    var checkbox=$("#checkbox").prop("checked");
                    /*if(check==""){
                        layer.msg("请选择个人企业性质",{shadeClose:true,shade:0.1,time:2000});
                    }
                    if(check1==""&&check2==""){
                        layer.msg("请选择个人企业性质",{shadeClose:true,shade:0.1,time:2000});
                    }
                    else if(check1!=""&&check2!=""){
                        layer.msg("请选择一种个人企业性质",{shadeClose:true,shade:0.1,time:2000});
                    }*/
                    if(sms==""){
                        layer.msg("请输入短信验证码",{shadeClose:true,shade:0.1,time:2000})
                    }
                    else if(trueName==""){
                        layer.msg("请输入真实姓名",{shadeClose:true,shade:0.1,time:2000})
                    }
                    else if(password==""){
                        layer.msg("请输入密码",{shadeClose:true,shade:0.1,time:2000})
                    }
                    else if(password.length<6){
                        layer.msg("密码不能少于6个字符",{shadeClose:true,shade:0.1,time:2000})
                    }
                    else if(password.length>20){
                        layer.msg("密码不能大于20个字符",{shadeClose:true,shade:0.1,time:2000})
                    }
                    else if(!password.match(/^[a-zA-Z]\w{5,19}$/)){
                        layer.msg("密码请以字母开头，只能包含字母、数字和下划线",{shadeClose:true,shade:0.1,time:2000})
                    }
                    else if(again==""){
                        layer.msg("请再次输入密码",{shadeClose:true,shade:0.1,time:2000})
                    }
                    else if(password!=again){
                        layer.msg("两次输入的密码不一致",{shadeClose:true,shade:0.1,time:2000})
                    }
                    else if(checkbox==""){
                        layer.msg("请勾选注册协议",{shadeClose:true,shade:0.1,time:2000})
                    }
                    else{
                        //http://localhost:8080/nsy-web/api/card/centerService?serviceCode=5001A02&sign=5f9e152adc8953f31487140d6c0982a590b2ca10&timestamp=20160627111123&nonce=123456789&editUser=zhangsan&editTime=20160627111127&device=iphone&ipaddr=192.168.1.111&mac=fa-ef-2d-34-fd&registerNum=15327198286&registerType=p&realyName=yxx&registerCompany=0&pwd=d123456
                        var index =layer.load(2,{content:"loading..."});
                        $.ajax({
                            type:"post",
                            url:"http://www.accecard.com/nsy-web/api/card/centerService",
                            data:{
                                serviceCode:"5001A02",
                                sign:"5f9e152adc8953f31487140d6c0982a590b2ca10",
                                timestamp:"20160627111123",
                                nonce:"123456789",
                                editUser:"zhangsan",
                                editTime:"20160627111127",
                                device:"iphone",
                                ipaddr:"192.168.1.111",
                                mac:"fa-ef-2d-34-fd",
                                registerNum:username,
                                registerType:"p",
                                realyName:trueName,
                                registerCompany:"1",
                                pwd: password
                            },
                            success:function(data){
                                var a=eval("("+data+")");
                                if(a.returnCode=="200"){
                                    layer.close(index);
                                    layer.msg("注册成功，请登录",{shadeClose:true,shade:0.1,time:2000});
                                    //setTimeout("window.location.href='Login.html'", 3000 );
                                }
                                else if(a.returnCode=="20010"){
                                    layer.close(index);
                                    layer.msg("注册失败",{shadeClose:true,shade:0.1,time:2000})
                                }
                                else if(a.returnCode=="20020"){
                                    layer.close(index);
                                    layer.msg("账号已注册成功",{shadeClose:true,shade:0.1,time:2000})
                                }
                                else if(a.returnCode=="20040"){
                                    layer.close(index);
                                    layer.msg("短信验证码验证失败",{shadeClose:true,shade:0.1,time:2000})
                                }
                                else{
                                    layer.close(index);
                                    layer.msg("注册失败",{time:3000});
                                }
                            }
                        })
                    }
                })
            }
        }
    });
</script>
